<template>
    <div>
        <el-table
                :data="tableData"
                style="width: 100%">
            <el-table-column
                    prop="date"
                    label="日期"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="name"
                    label="姓名"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="address"
                    label="地址">
            </el-table-column>
        </el-table>
        <button value="demo" @click="dj()"></button>
    </div>
</template>

<script>
    export default {
        name: 'demo',
        data() {
            return {
                tableData: [{
                    date: '2016-05-02',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1518 弄',
                    hhh:"啥也不是,最后一次测试占位，如有显示错误进行过呢更改"
                }, {
                    date: '2016-05-04',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1517 弄',
                    hhh:"啥也不是,最后一次测试占位，如有显示错误进行过呢更改"
                }, {
                    date: '2016-05-01',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1519 弄',
                    hhh:"啥也不是,最后一次测试占位，如有显示错误进行过呢更改"
                }, {
                    date: '2016-05-03',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1516 弄',
                    hhh:"啥也不是,最后一次测试占位，如有显示错误进行过呢更改"
                }]
            }
        },
        methods:{
            dj() {
                //excel数据导出
                require.ensure([], () => {
                    const {
                        export_json_to_excel
                    } = require('../js/Export2Excel');
                    const tHeader = ['序号','省份', '投资总额','占位'];
                    const filterVal = ['name','date', 'address','hhh'];
                    const list = this.tableData;
                    const data = this.formatJson(filterVal, list);
                    export_json_to_excel(tHeader, data, '列表excel');
                })
            },
            formatJson(filterVal, jsonData) {
                return jsonData.map(v => filterVal.map(j => v[j]))
            }


        }
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
    h3 {
        margin: 40px 0 0;
    }
    ul {
        list-style-type: none;
        padding: 0;
    }
    li {
        display: inline-block;
        margin: 0 10px;
    }
    a {
        color: #42b983;
    }
</style>
